﻿using System;

namespace EventScavenger
{
    public class NameProperty : Attribute
    {
        public string Name;
    }
    public class EventEntry : IComparable
    {
        private static int _nextId = 1;
        private int _id = _nextId++;

        private int machineLogId;
        [NameProperty(Name = "MachineId")]
        public int MachineLogId
        {
            get { return machineLogId; }
            set { machineLogId = value; }
        }
        private string machineName;
        [NameProperty(Name = "Machine")]
        public string MachineName
        {
            get { return machineName; }
            set { machineName = value; }
        }
        private string logName;
        [NameProperty(Name = "Log")]
        public string LogName
        {
            get { return logName; }
            set { logName = value; }
        }
        private int recordNumber;
        [NameProperty(Name = "RecordNo")]
        public int RecordNumber
        {
            get { return recordNumber; }
            set { recordNumber = value; }
        }
        private int eventID;
        [NameProperty(Name = "EventID")]
        public int EventID
        {
            get { return eventID; }
            set { eventID = value; }
        }
        private DateTime timeGenerated;
        [NameProperty(Name = "Date")]
        public DateTime TimeGenerated
        {
            get { return timeGenerated; }
            set { timeGenerated = value; }
        }
        private string sourceName;
        [NameProperty(Name = "Source")]
        public string SourceName
        {
            get { return sourceName; }
            set { sourceName = value; }
        }
        private string eventTypeName;
        [NameProperty(Name = "Type")]
        public string EventTypeName
        {
            get { return eventTypeName; }
            set { eventTypeName = value; }
        }
        private string message;
        [NameProperty(Name = "Message")]
        public string Message
        {
            get { return message; }
            set { message = value; }
        }
        private string userName;
        [NameProperty(Name = "User")]
        public string UserName
        {
            get { return userName; }
            set { userName = value; }
        }
        private string category;
        public string Category
        {
            get { return category; }
            set { category = value; }
        }
        private int repeat;
        [NameProperty(Name = "Repeat")]
        public int Repeat
        {
            get { return repeat; }
            set { repeat = value; }
        }

        public bool Equal(EventEntry entry)
        {
            return (
                machineName == entry.machineName &&
                LogName == entry.logName &&
                recordNumber == entry.recordNumber
                );
        }

        public override string ToString()
        {
            return machineName + "\\" + logName + "\\" + sourceName + "\\" + eventTypeName + "\\" + timeGenerated.ToString("yyyyMMddHHmmss");
        }

        #region IComparable Members
        public int CompareTo(object obj)
        {
            EventEntry p = obj as EventEntry;
            if (p == null)
                return -1;
            return this._id - p._id;
        }
        #endregion
    }
}
